

package example.serialization;

import com.hazelcast.nio.serialization.compact.CompactReader;
import com.hazelcast.nio.serialization.compact.CompactSerializer;
import com.hazelcast.nio.serialization.compact.CompactWriter;

import javax.annotation.Nonnull;
import java.util.Objects;
import java.util.UUID;

public class CustomUUIDSerializer implements CompactSerializer<UUID> {

    @Nonnull
    @Override
    public UUID read(@Nonnull CompactReader reader) {
        return UUID.fromString(Objects.requireNonNull(reader.readString("uuidField")));
    }

    @Override
    public void write(@Nonnull CompactWriter writer, @Nonnull UUID object) {
        writer.writeString("uuidField", object.toString());
    }

    @Nonnull
    @Override
    public String getTypeName() {
        return "myUUID";
    }

    @Nonnull
    @Override
    public Class<UUID> getCompactClass() {
        return UUID.class;
    }

}
